Add manual profile triggering and cooldown mechanism#4730
Draft
johnoliver wants to merge 3 commits into
Draft
Conversation
- Creating/Touching a file at a well known location, by default "<temp_dir>/applicationinsights-agent-profile-trigger" - Add a JMX mbean, can be called via "jcmd <pid> MBean.invoke com.microsoft:type=AI-alert,name=ProfilerControl triggerProfile" - Add a global cooldown on the profile to ensure that we dont get repeat profiles from multiple sources
There was a problem hiding this comment.
Pull request overview
Adds operator-initiated profiling to the Application Insights Java agent (file-based trigger + JMX MBean) and introduces a cross-trigger global cooldown to reduce rapid back-to-back recordings from different trigger sources.
Changes:
- Added manual profile triggering via (1) a “touch file” trigger and (2) a JMX MBean (
ProfilerControl). - Added a global profiler cooldown (
globalCooldownSeconds) enforced across CPU/memory/request/manual/periodic triggers. - Updated docs and tests, including new test suites for file-trigger behavior and global cooldown.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/README.md | Documents new profiler settings and manual triggering mechanisms. |
| agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/profiler/triggers/GcEventInitTest.java | Updates test wiring for new AlertingSubsystem.create(...) signature. |
| agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/profiler/triggers/AlertTriggerSpanProcessorTest.java | Updates test wiring for new AlertingSubsystem.create(...) signature. |
| agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/profiler/ProfilerGlobalCooldownTest.java | Adds tests for new global cooldown behavior. |
| agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/profiler/ProfilerControlTest.java | Adds tests for JMX MBean registration and triggering behavior. |
| agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/profiler/triggers/AlertingSubsystemInit.java | Wires file-trigger config into alerting subsystem and optionally registers the profiler control MBean. |
| agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/profiler/ProfilingInitializer.java | Ensures file-trigger evaluation is performed on the config polling cycle. |
| agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/profiler/ProfilerControlMBean.java | Introduces the JMX MBean interface for manual triggering. |
| agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/profiler/ProfilerControl.java | Implements and registers the JMX MBean that emits MANUAL alert breaches. |
| agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/profiler/Profiler.java | Adds global cooldown enforcement and a TimeSource for deterministic time handling. |
| agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/profiler/PerformanceMonitoringService.java | Builds/resolves the file-trigger config and exposes evaluateFileTrigger(). |
| agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/Configuration.java | Adds config fields for manual settings, global cooldown, MBean enablement, and file trigger settings. |
| agent/agent-profiler/request-triggers.md | Notes that global cooldown suppresses all triggers. |
| agent/agent-profiler/agent-alerting/src/test/java/com/microsoft/applicationinsights/alerting/TestTimeSource.java | Adds ability to set “now” for tests. |
| agent/agent-profiler/agent-alerting/src/test/java/com/microsoft/applicationinsights/alerting/AlertingSubsystemTest.java | Updates test wiring for new AlertingSubsystem.create(...) signature. |
| agent/agent-profiler/agent-alerting/src/test/java/com/microsoft/applicationinsights/alerting/AlertingSubsystemFileTriggerTest.java | Adds test coverage for file-trigger scenarios. |
| agent/agent-profiler/agent-alerting/src/main/java/com/microsoft/applicationinsights/alerting/AlertingSubsystem.java | Implements file-trigger evaluation and refactors manual-trigger evaluation. |
| agent/agent-profiler/agent-alerting-api/src/main/java/com/microsoft/applicationinsights/alerting/config/AlertingProfileFileTriggerConfiguration.java | Introduces configuration object for the file-based manual trigger. |
Comments suppressed due to low confidence (1)
agent/agent-profiler/agent-alerting/src/main/java/com/microsoft/applicationinsights/alerting/AlertingSubsystem.java:181
evaluateCollectionPlanTrigger()usesInstant.now()for expiration checks while the rest of the alerting subsystem uses the injectedTimeSource. This makes behavior inconsistent (and harder to test) when a non-defaultTimeSourceis provided. Consider usingtimeSource.getNow()here as well.
boolean shouldTrigger =
config.isSingle()
&& config.getMode() == EngineMode.immediate
&& Instant.now().isBefore(config.getExpiration())
&& !manualTriggersExecuted.contains(config.getSettingsMoniker());
Comment on lines
+236
to
+239
| CollectionPlanConfiguration collectionPlan = alertConfig.getCollectionPlanConfiguration(); | ||
| int durationSeconds = collectionPlan.getImmediateProfilingDurationSeconds(); | ||
| if (durationSeconds <= 0) { | ||
| durationSeconds = alertingProfileFileTriggerConfiguration.getDefaultProfileDurationSeconds(); |
Comment on lines
+62
to
+66
| FlightRecorderConnection frc = mock(FlightRecorderConnection.class); | ||
| when(frc.newRecording(any(), any())).thenReturn(mock(Recording.class)); | ||
|
|
||
| profiler.initialize(mock(UploadService.class), Executors.newScheduledThreadPool(1), frc); | ||
| return profiler; |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request adds support for triggering manual profiling triggering profiles via 2 routes:
Additionally this pr adds a global cooldown on the profile to ensure that we dont get repeat profiles from multiple sources
File-based manual profiling trigger:
AlertingProfileFileTriggerConfiguration, a new configuration class that controls the file-based manual profile trigger, including enablement, file path resolution, and default profile duration.AlertingSubsystemto support the file-based trigger: checks for the presence and recency of the trigger file, deletes it after use, and initiates a manual profile when appropriate. The subsystem now accepts the file trigger configuration as a dependency and has been refactored to evaluate both collection plan and file-based triggers. [1] [2] [3] [4] [5]Testing enhancements:
AlertingSubsystemFileTriggerTest, a new test suite covering scenarios for the file-based trigger, such as firing when the file exists and is recent, not firing when disabled, not firing for old or missing files, and correct profile duration selection.AlertingSubsystemTest) to use the new configuration and maintain compatibility. [1] [2] [3] [4]TestTimeSourceto allow setting the current time, supporting precise control in tests.Documentation:
request-triggers.mdthat a global cooldown is enforced after any profile recording, affecting all trigger types, including the new file-based manual trigger.